package com.online.servlet.shop;

import com.online.pojo.User;
import com.online.pojo.menu;
import com.online.pojo.merchant;
import com.online.service.user.Impl.ShopServiceImpl;
import com.online.service.user.Impl.UserServiceImpl;
import com.online.service.user.Impl.merchantServiceImpl;
import com.online.service.user.ShopService;
import com.online.service.user.UserService;
import com.online.service.user.merchantService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class addMenuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String user_name = req.getParameter("user_name");
        String shop_name = req.getParameter("shop_name");
        double price = Double.parseDouble(req.getParameter("price"));
        String type = req.getParameter("type");
        merchantService merchantService = new merchantServiceImpl();
            merchantService.insert(name, shop_name, price, type);
            try {
                merchant shop;
                shop= merchantService.login(user_name);

                List<menu> list = new ArrayList<menu>();
                merchantService.select(list,shop_name);
                req.setAttribute("shop_name",shop.getShop_name());
                req.setAttribute("user_name",shop.getUser_name());
                req.setAttribute("account",shop.getAccount());
                req.setAttribute("menu",list);
                req.getRequestDispatcher("/jsp/Merchantback.jsp").forward(req, resp);
            } catch (SQLException e) {
                e.printStackTrace();
            }

    }
}
